package cn.com.KnowNews.servlet;

import cn.com.KnowNews.service.ICategoryService;
import cn.com.KnowNews.service.imlp.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddCateServlet",urlPatterns = "/AddCate")
public class AddCateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cate = request.getParameter("catename");
        String adder =request.getParameter("addername");
        ICategoryService categoryService = new CategoryServiceImpl();
        try {
            categoryService.addCate(cate,adder);
            response.sendRedirect("/ShowAllCategory");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
